﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using TaskScheduler;

public partial class System_TaskScheduler : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var scheduler=new ScheduledTasks();

        var q = from task in scheduler.GetTaskNames()
                select scheduler.OpenTask(task);        

        

        lvTasks.DataSource = q;
        lvTasks.DataBind();
    }

    protected string GetLastRun(object dataItem)
    {
        var task = (Task)dataItem;        

        if (task.MostRecentRunTime == DateTime.MinValue)
        {
            return "&lt;Never run&gt;";
        }
        else
        {
            return task.MostRecentRunTime.ToString();
        }
    }

    protected string GetAccount(object dataItem)
    {
        var task = (Task)dataItem;

        try
        {
            return task.AccountName;
        }
        catch (Exception)
        {
            return "&lt;Unknown&gt;";            
        }
    }
}
